//
//  Extension+String.swift
//  ZDKBaseKit
//
//  Created by Killua on 2017/9/22.
//  Copyright © 2017年 JingZhong. All rights reserved.
//

import Foundation
import UIKit

extension String {
    /// 返回字符串的size
    ///
    /// - Parameters:
    ///   - font: 字体
    ///   - maxSize: 最大size
    ///   - lineMargin: 行间距
    /// - Returns: CGSize
    func sizeWith(_ font : UIFont , _ maxSize : CGSize , _ lineMargin : CGFloat) -> CGSize {
        let options = NSStringDrawingOptions.usesLineFragmentOrigin
        let paragraphStyle : NSMutableParagraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = lineMargin
        var attributes : [NSAttributedStringKey : Any] = [:]
        attributes[.font] = font
        attributes[.paragraphStyle] = paragraphStyle
        let textBouds = self.boundingRect(with: maxSize,
                                          options: options,
                                          attributes: attributes,
                                          context: nil)
        return textBouds.size
    }
}
